import axios from 'axios'
// axios.defaults.timeout = 10000
axios.defaults.headers.post['Content-Type'] = 'application/x-www=form-urlencoded'
const baseUrl = '/api'
export default {
  fetchGet(url, params) {
    return new Promise((resolve, reject) => {
      axios
        .get(baseUrl + url, params)
        .then((res) => {
          resolve(res.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  fetchQuickSearch(url) {
    return new Promise((resolve, reject) => {
      axios
        .get(baseUrl + url)
        .then((res) => {
          resolve(res.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  fetchPost(url, params = {}) {
    return new Promise((resolve, reject) => {
      axios
        .post(baseUrl + url, params, {
          headers: {
            'content-type': 'application/json'
          }
        })
        .then((res) => {
          resolve(res.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  }
}
